Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

300
Vistas
How to return the data not [object object] JS

I am tring to print just the the lists and tasks i get an [object object]

here is my code :

const users = {
  user1: {
    lists: [
      {
        id: 0,
        name: "Work",
        tasks: [
          {
            id: 0,
            task: "task to do",
          },
          {
            id: 1,
            task: "task to do",
          },
        ],
      },
      {
        id: 1,
        name: "Holiday",
        tasks: [
          {
            id: 0,
            task: "task to do",
          },
          {
            id: 1,
            task: "task to do",
          },
        ],
      },
      {
        id: 3,
        name: "New List",
        tasks: [],
      },
    ],
  },
};

and this what i tried:

$.each(users, function (key, value) {
  const keys = key;
  console.log(keys)
  let test = users[key];
  console.log(test)
  $.each(test, function (key, value) {
    value;
    console.log(value)
  $.each(value, function (key, value) {
    value.name
    document.write(value.name)
    document.write(value.tasks)
  })
  });
});

this what it returns:

Work[object Object],[object Object]Holiday[object Object],[object Object]New List

my questions:

  • how i return the list alone , and tasks alone?
  • is there any problem with my data structure?

i am just beginner

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First, I will ask that you try not to use jQuery ($) for everything when it's not needed.

Secondly, you have a variable called users, which I would think should be an array, but you have it down as a keyed object. Might be worth looking into.

Anyway, I'll try to help you with the "list alone" and "tasks alone"-stuff!

const users={user1:{lists:[{id:0,name:"Work",tasks:[{id:0,task:"task to do"},{id:1,task:"task to do"}]},{id:1,name:"Holiday",tasks:[{id:0,task:"task to do"},{id:1,task:"task to do"}]},{id:3,name:"New List",tasks:[]}]}}

const allLists = []


// id is "user1", user is the user-object.
for(const [id, user] of Object.entries(users)) {
  const lists = user.lists
  for(const list of lists) {
    allLists.push(list)
  }
}


console.log(`ALL LISTS: ${allLists}`) // Lots of "[object Object]"
console.log(`ALL LISTS: ${JSON.stringify(allLists)}`) // This one works

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda